function setGoodsList(bookList, size) {
    let goodsList = $(".goodsList");
    goodsList.empty();
    let tempRowCount = size / 4;
    let division = 4;
    let rowCount = parseInt(tempRowCount);
    if (rowCount < tempRowCount) {
        rowCount = rowCount + 1;
        division = size % 4;
    }
    for (let i = 0; i < rowCount; i++){
        let goodsRow = $("<div class=\"row goods-row\"></div>")
        goodsList.append(goodsRow);
        let cloumn = 4;
        if (i === rowCount - 1){
            cloumn = division;
        }
        for(let j = i * 4, k = j + cloumn; j < k; j++){

            // //建立DOM对象
            let item = $("<div class=\"col-md-3\"></div>");
            let card = $("<div class=\"card\"></div>");
            let bId = $("<input type=\"hidden\">")
            let img = $("<img src= alt=\"Avatar\" style=\"width:100%\">");
            let caption = $("<div class=\"caption\" style=\"padding:3px\"></div>");
            let caption_1 = $("<div class=\"caption_1\"></div>");
            let price = $("<div class=\"price\"></div>");
            let sales = $("<div class=\"sales\"></div>");
            let caption_2 = $("<div class=\"caption_2\"></div>");
            let caption_3 = $("<div class=\"caption_3\"></div>");
            let caption_4 = $("<div class=\"caption_4\"></div>");
            let bookName = $("<p></p>");
            let author = $("<p></p>");
            let stock = $("<p></p>");

            //给值
            let bookItem = bookList[j];
            bId.val(bookItem["bId"]);
            img.attr("src", bookItem["img_path"]);
            img.val(bookItem["img_path"]);
            price.text("￥"+bookItem["price"]);
            sales.text("已经有" + bookItem["sales"] + "人购买");
            bookName.text(bookItem["bookName"]);
            author.text(bookItem["author"]);
            stock.text("库存" + bookItem["stock"] + "本");

            //嵌入
            item.append(card);
            card.append(bId);
            card.append(img);
            card.append(caption);
            caption.append(caption_1);
            caption_1.append(price);
            caption_1.append(sales);
            caption.append(caption_2);
            caption_2.append(bookName);
            caption.append(caption_3);
            caption_3.append(author);
            caption.append(caption_4);
            caption_4.append(stock);
            goodsRow.append(item);
        }
    }
}

// 给分页栏加上信息和绑定功能
function setPageNav (data) {
    let pagination = $(".pagination");
    let navPageNumItems = pagination.children(".pageNumber");
    let navPageNums = data["navigatepageNums"];
    let hasPreviousPage = data["hasPreviousPage"];
    let hasNextPage = data["hasNextPage"];
    let pageNum = data["pageNum"];
    let pages = data["pages"];

    //判定是否有前一页并设置是否点击
    let previousPageDom = $("#previousPage");
    if (hasPreviousPage) {
        let previousPageNum = pageNum - 1;
        previousPageDom.children().attr("href","new?page=" + previousPageNum);
        previousPageDom.show();
    } else {
        previousPageDom.hide();
    }

    //判定是否有后一页并设置是否点击
    let nextPageNumDom = $("#nextPage");
    if (hasNextPage) {
        let nextPageNum = pageNum + 1;
        nextPageNumDom.children().attr("href","new?page=" + nextPageNum);
        nextPageNumDom.show();
    } else {
        nextPageNumDom.hide();
    }

    //页数
    for(let i = 0; i < navPageNumItems.length; i++){
        let navPageNumItem = $(navPageNumItems[i]);
        let navPageItem = navPageNumItem.children();
        let navPageNum = navPageNums[i];
        navPageItem.text(navPageNum);
        navPageItem.attr("href","new?page=" + navPageNum);
        if (navPageNum === pageNum){
            navPageNumItem.addClass("active");
        }
    }

    //总页数
    let totalPageDom = $(".totalPage");
    totalPageDom.text(pages);

    // 当前页数
    let pageCountDom = $(".pageCount");
    pageCountDom.val(pageNum);

    // 页数跳转
    let pageJumpDom = $(".pageJump");
    pageJumpDom.click(function () {
        let pageCount = pageCountDom.val();
        window.location.href = "new?page=" + pageCount;
    });

}

// 给分页栏加上信息和绑定功能
function showPageNavWithKeyword (data, keyword) {
    let pagination = $(".pagination");
    let navPageNumItems = pagination.children(".pageNumber");
    let navPageNums = data["navigatepageNums"];
    let hasPreviousPage = data["hasPreviousPage"];
    let hasNextPage = data["hasNextPage"];
    let pageNum = data["pageNum"];
    let pages = data["pages"];

    //判定是否有前一页并设置是否点击
    let previousPageDom = $("#previousPage");
    if (hasPreviousPage) {
        let previousPageNum = pageNum - 1;
        previousPageDom.children().attr("href","new?keyword=" + keyword + "&page=" + previousPageNum);
        previousPageDom.show();
    } else {
        previousPageDom.hide();
    }

    //判定是否有后一页并设置是否点击
    let nextPageNumDom = $("#nextPage");
    if (hasNextPage) {
        let nextPageNum = pageNum + 1;
        nextPageNumDom.children().attr("href","new?keyword=" + keyword + "&page=" + nextPageNum);
        nextPageNumDom.show();
    } else {
        nextPageNumDom.hide();
    }

    //页数
    for(let i = 0; i < navPageNumItems.length; i++){
        let navPageNumItem = $(navPageNumItems[i]);
        let navPageItem = navPageNumItem.children();
        let navPageNum = navPageNums[i];
        navPageItem.text(navPageNum);
        navPageItem.attr("href","new?keyword=" + keyword + "&page=" + navPageNum);
        if (navPageNum === pageNum){
            navPageNumItem.addClass("active");
        }
    }

    //总页数
    let totalPageDom = $(".totalPage");
    totalPageDom.text(pages);

    // 当前页数
    let pageCountDom = $(".pageCount");
    pageCountDom.val(pageNum);

    // 页数跳转
    let pageJumpDom = $(".pageJump");
    pageJumpDom.click(function () {
        let pageCount = pageCountDom.val();
        window.location.href = "new?page=" + pageCount;
    });

}

//获取URL参数
function getQueryVariable() {
    let href = window.location.href;
    let query = href.substring(href.indexOf('?') + 1);
    let vars = query.split("&");
    let obj = {}
    for (let i = 0; i < vars.length; i++) {
        let pair = vars[i].split("=");
        obj[pair[0]] = pair[1]
    }
    return obj;
}